package appfuse.framework.util;

public class TokenUtil 
{
	private static String m_strKey = "13CDAEA1-547C-47e3-A122-BF3DA3A81C7F";

	public static String makeToken(String strSeed)
	{
		String strRet = "";
		String strTime = System.currentTimeMillis() + "";
		String strMd5 = MD5.crypt(strSeed + m_strKey + strTime);
		strRet = BASE64Encrypt.encode(strSeed +","+ strMd5 +","+ strTime, "UTF-8");
		return strRet;
	}
	
	public static String VaildToken(String strToken)
	{
		String strSeed = "";
		String strRet = BASE64Encrypt.decode(strToken, "UTF-8");
		String[] strArr = strRet.split(",");
		if (strArr.length > 2)
		{
			String strOrgSeed = strArr[0];
			String strMd5 = strArr[1];
			String strTime = strArr[2];
			long lCurTime = System.currentTimeMillis();
			strRet = MD5.crypt(strOrgSeed + m_strKey + strTime);
			//token在一个月内有效
			if (strMd5.equals(strRet) == true &&
				(lCurTime - new Long(strTime))/1000 < 2592000)
			{
				strSeed = strOrgSeed;
			}
		}
		return strSeed;
	}
}
